package com.timous.链表;

/**
 * @author Timous
 * @create 2020-12-22 15:19
 **/
public class _141_环形链表 {
    public boolean hasCycle(ListNode head) {
        if(head == null || head.next == null){
            return false;
        }
        ListNode slow = head.next;
        ListNode fast = head.next.next;
        //快的走2步 ， 慢的走一步 ， 快指针先达到null的时候就走到了null
        while (fast != null && fast.next != null){
            if (slow.val == fast.val){
                return true;
            }
            slow = slow.next;
            fast = fast.next.next;
        }
        return false;
    }
}
